using System;
using System.Collections.Generic;
using System.Text;

namespace TidhiGanitam.DataModel
{
    public class Tidhi : DegreeEntity
    {
        #region properties
        public double Tidhulu
        {
            get
            {
                double dTidhulu = MathHelper.GetDegrees(dDegrees);
                return dTidhulu % 30;
            }
        }
        public double Ghadiyalu
        {
            get
            {
                return MathHelper.GetMinutes(dDegrees);
            }
        }
        public double Vighadiyalu
        {
            get
            {
                return MathHelper.GetSeconds(dDegrees);
            }
        }
        public double Paralu
        {
            get
            {
                return MathHelper.GetMilliSeconds(dDegrees);
            }
        }
        public override string ToString()
        {
            string sRetString = string.Empty;
            sRetString = string.Format("{0}-{1}-{2}-{3}", Tidhulu.ToString(),
                                                 Ghadiyalu.ToString(),
                                                 Vighadiyalu.ToString(),
                                                 Paralu.ToString());
            return sRetString;
        }
        #endregion

        public Tidhi()
            : base()
        {
        }
        public Tidhi(Tidhi tidhi)
            : base((DegreeEntity)tidhi)
        {
        }
        public Tidhi(double tidhi, double ghadiyalu, double vighadiyalu,
                double paralu)
            : base(tidhi, ghadiyalu, vighadiyalu, paralu)
        {
        }
        public Tidhi(double tidhi, double ghadiyalu, double vighadiyalu)
            : base(tidhi, ghadiyalu, vighadiyalu, 0)
        {
        }
        public Tidhi(double tidhi, double ghadiyalu)
            : base(tidhi, ghadiyalu, 0, 0)
        {
        }
        public Tidhi(double tidhi)
            : base(tidhi)
        {
        }

        #region operator overloading routines

        public static Tidhi operator +(Tidhi op1, Tidhi op2)
        {
            Tidhi RetVal = new Tidhi();
            RetVal.dDegrees = op1.dDegrees + op2.dDegrees;
            RetVal.Refresh();
            return RetVal;
        }
        public void Refresh()
        {
            this.dDegrees = dDegrees % 30;
        }
        public static Tidhi operator +(Tidhi op1, double op2)
        {
            Tidhi RetVal = new Tidhi();
            RetVal.dDegrees = op1.dDegrees + op2;
            RetVal.Refresh();
            return RetVal;
        }
        public static Tidhi operator -(Tidhi op1, Tidhi op2)
        {
            Tidhi RetVal = new Tidhi();
            if (op1 < op2)
            {
                op1.dDegrees += 30d;
            }
            RetVal.dDegrees = op1.dDegrees - op2.dDegrees;
            RetVal.Refresh();
            return RetVal;
        }
        public static Tidhi operator -(Tidhi op1, double op2)
        {
            Tidhi RetVal = new Tidhi();
            if (op1.dDegrees < op2)
            {
                op1.dDegrees += 30d;
            }
            RetVal.dDegrees = op1.dDegrees - op2;
            RetVal.Refresh();
            return RetVal;
        }
        public static Tidhi operator *(Tidhi op1, Tidhi op2)
        {
            Tidhi RetVal = new Tidhi();
            RetVal.dDegrees = op1.dDegrees * op2.dDegrees;
            RetVal.Refresh();
            return RetVal;
        }
        public static Tidhi operator *(Tidhi op1, double op2)
        {
            Tidhi RetVal = new Tidhi();
            RetVal.dDegrees = op1.dDegrees * op2;
            RetVal.Refresh();
            return RetVal;
        }
        public static Tidhi operator /(Tidhi op1, Tidhi op2)
        {
            Tidhi RetVal = new Tidhi();
            if (op2.dDegrees != 0)
            {
                RetVal.dDegrees = op1.dDegrees / op2.dDegrees;
            }
            RetVal.Refresh();
            return RetVal;
        }
        public static Tidhi operator /(Tidhi op1, double op2)
        {
            Tidhi RetVal = new Tidhi();
            if (op2 != 0)
            {
                RetVal.dDegrees = op1.dDegrees / op2;
            }
            RetVal.Refresh();
            return RetVal;
        }
        public static bool operator >(Tidhi op1, Tidhi op2)
        {
            bool ReturnValue = false;
            if (op1.dDegrees > op2.dDegrees)
            {
                ReturnValue = true;
            }
            return ReturnValue;
        }
        public static bool operator >=(Tidhi op1, Tidhi op2)
        {
            bool ReturnValue = false;
            if (op1.dDegrees >= op2.dDegrees)
            {
                ReturnValue = true;
            }
            return ReturnValue;
        }
        public static bool operator ==(Tidhi op1, Tidhi op2)
        {
            bool ReturnValue = false;
            if (op1.dDegrees == op2.dDegrees)
            {
                ReturnValue = true;
            }
            return ReturnValue;
        }
        public static bool operator <(Tidhi op1, Tidhi op2)
        {
            bool ReturnValue = false;
            if (op1.dDegrees < op2.dDegrees)
            {
                ReturnValue = true;
            }
            return ReturnValue;
        }
        public static bool operator <=(Tidhi op1, Tidhi op2)
        {
            bool ReturnValue = false;
            if (op1.dDegrees < op2.dDegrees)
            {
                ReturnValue = true;
            }
            return ReturnValue;
        }
        public static bool operator !=(Tidhi op1, Tidhi op2)
        {
            bool ReturnValue = false;
            if (op1.dDegrees != op2.dDegrees)
            {
                ReturnValue = true;
            }
            return ReturnValue;
        }
        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        #endregion

    }
}
